from core.support import set_cutscene, get_game
from core.item import Item
from core.action import Action
from rooms.gradlounge import GradLounge
from items.neil import Neil
from items.mary import Mary
from core.game import Game

class buid(Item):
    def __init__(self):
        Item.__init__(self, "BUid")    # do basic initialization for every item
        
        # build list of actions
        # are we going to do a swipe action?  or just check if the card is in inventory?
        # if we just check, then we don't need this action at all
        self.add_action(SwipeCard)
    
    def get_description(self):
        return "BUid"

# define actions for this item

class SwipeCard(Action):
    def __init__(self):
        Action.__init__(self, "swipe_card")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Swipe BU id"
    
    # only show button if grad lounge is locked
    def is_enabled(self):
        game = get_game()
        if game.history[-1].get_id() == 'gradlounge':
            if game.get_room('gradlounge', GradLounge).locked:
                return True           
            else:
                return False
        else:
            return False
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    # only works in grad lounge
    def do_action(self,game,room,request):
        game = get_game()
        player = game.get_player()
        if room.get_id() == 'gradlounge':
            if room.locked:
                    room.locked = False
                   # room.solving = True
                    if 'neil' not in player.inventory:
                        room.add_item(Neil())
                    if 'mary' not in player.inventory:
                        room.add_item(Mary())
            else:
                set_cutscene("The Grad Lounge is already unlocked.")
        else:
            set_cutscene("There are no locked doors here.")
        return